package com.sise.cn.exception;

import com.sise.cn.enums.error.SystemError;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @ClassName SystemException
 * @Description
 * @Author CCJ
 * @Date 2020/6/1 22:40
 **/
@Data
@AllArgsConstructor
public class SystemException extends RuntimeException {
    private int code;

    private String msg;

    private SystemError error;

    private static final int ERROR = -999;

    public SystemException(SystemError error, String param) {
        this.error = error;
        this.msg = param;
    }

    public SystemException(String msg) {
        this.code = ERROR;
        this.msg = msg;
    }

    public SystemException(SystemError systemError) {
        this.code = systemError.getCode();
        this.msg = systemError.getMessage();
    }

    public SystemException(SystemError systemError, Object... param) {
        this.code = systemError.getCode();
        this.msg = String.format(systemError.getMessage(), param);
    }
}
